package com.icode.core.dto.house;

import org.springframework.web.multipart.MultipartFile;
import com.icode.core.model.house.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lb
 * Date: 15-11-13
 * Time: 下午5:15
 * To change this template use File | Settings | File Templates.
 */
public class BannerForAppDTO {

    private String guid;

    private List<MultipartFile> firstImages;
    private MultipartFile secondImage;

    private List<FirstBanners> firstBannerses;
    private UploadImage secondBannerse;

    private List<String> firstImageGuids;
    private String secondImageGuid;

    private List<String> firstBannersesGuid;
    private String secondBannersesGuid;

    public List<String> getFirstBannersesGuid() {
        return firstBannersesGuid;
    }

    public void setFirstBannersesGuid(List<String> firstBannersesGuid) {
        this.firstBannersesGuid = firstBannersesGuid;
    }

    public String getSecondBannersesGuid() {
        return secondBannersesGuid;
    }

    public void setSecondBannersesGuid(String secondBannersesGuid) {
        this.secondBannersesGuid = secondBannersesGuid;
    }

    public List<String> getFirstImageGuids() {
        return firstImageGuids;
    }

    public void setFirstImageGuids(List<String> firstImageGuids) {
        this.firstImageGuids = firstImageGuids;
    }

    public String getSecondImageGuid() {
        return secondImageGuid;
    }

    public void setSecondImageGuid(String secondImageGuid) {
        this.secondImageGuid = secondImageGuid;
    }

    public List<FirstBanners> getFirstBannerses() {
        return firstBannerses;
    }

    public void setFirstBannerses(List<FirstBanners> firstBannerses) {
        this.firstBannerses = firstBannerses;
    }

    public UploadImage getSecondBannerse() {
        return secondBannerse;
    }

    public void setSecondBannerse(UploadImage secondBannerse) {
        this.secondBannerse = secondBannerse;
    }

    public BannerForAppDTO() {
    }

    public BannerForAppDTO(String guid, List<MultipartFile> firstImages, MultipartFile secondImage) {
        this.guid = guid;
        this.firstImages = firstImages;
        this.secondImage = secondImage;
    }

    public void setFirstImages(List<MultipartFile> firstImages) {
        this.firstImages = firstImages;
    }

    public BannerForAppDTO(String guid, List<String> firstImageGuids, String secondImageGuid, List<String> firstBannersesGuid, String secondBannersesGuid) {
        this.guid = guid;
        this.firstImageGuids = firstImageGuids;
        this.secondImageGuid = secondImageGuid;
        this.firstBannersesGuid = firstBannersesGuid;
        this.secondBannersesGuid = secondBannersesGuid;
    }

    public static List<BannerForAppDTO> toDTOs(List<BannerForApp> bannerForApps) {
        List<BannerForAppDTO> bannerForAppDTOs = new ArrayList<>();
        for (BannerForApp bannerForApp : bannerForApps) {
            BannerForAppDTO bannerForAppDTO = toDTO(bannerForApp);
            bannerForAppDTOs.add(bannerForAppDTO);
        }
        return bannerForAppDTOs;
    }

    public static BannerForAppDTO toDTO(BannerForApp bannerForApp) {
        List<String> firstImageGuids = new ArrayList<>();
        List<FirstBanners> firstBannerses = bannerForApp.firstBanners();

        List<String> firstBannersesGuid = new ArrayList<>();

        for (FirstBanners firstBanners : firstBannerses) {
            String guid0 = firstBanners.guid();
            String guid = firstBanners.image().guid();
            firstImageGuids.add(guid);
            firstBannersesGuid.add(guid0);
        }

        UploadImage image = bannerForApp.secondBanner();
        String secondImageGuid = null;
        String secondBannersesGuid = null;
        if (image != null) {
            secondImageGuid = image.guid();
            secondBannersesGuid = image.guid();
        }

        return new BannerForAppDTO(bannerForApp.guid(), firstImageGuids, secondImageGuid, firstBannersesGuid, secondBannersesGuid);
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }


    public MultipartFile getSecondImage() {
        return secondImage;
    }

    public void setSecondImage(MultipartFile secondImage) {
        this.secondImage = secondImage;
    }

    public List<MultipartFile> getFirstImages() {
        return firstImages;
    }
}
